package com.huluobo.a2111douyindemo.mine;


import android.util.Log;

import androidx.recyclerview.widget.GridLayoutManager;

import com.blankj.utilcode.util.ToastUtils;
import com.huluobo.a2111douyindemo.R;
import com.huluobo.a2111douyindemo.adapter.WorkAdapter;
import com.huluobo.a2111douyindemo.databinding.FragmentWorksBinding;
import com.huluobo.mvvm_base.mvvm.base.view.BaseMVVMFragment;
import com.huluobo.mvvm_base.mvvm.bean.GetLikeVideoBeanResult;

import java.util.ArrayList;
import java.util.List;

public class WorksFragment extends BaseMVVMFragment<FragmentWorksBinding, WorksViewModel> {
    private WorkAdapter workAdapter;

    private List<GetLikeVideoBeanResult.GetLikeVideoBean> likeVideoBeans = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_works;
    }

    @Override
    protected void initData() {
        viewModel.getLikeVideos();

        viewModel.success.observe(this, getLikeVideoBeanResult -> {
            if (getLikeVideoBeanResult.getCode() == 200) {
                likeVideoBeans.clear();
                likeVideoBeans.addAll(getLikeVideoBeanResult.getData());
                workAdapter.notifyDataSetChanged();
            } else {
                ToastUtils.showLong(getLikeVideoBeanResult.getMessage());
            }
        });

        viewModel.failed.observe(this, s -> {
            Log.i("TagA", "getLikeVideos:" + s);
        });
    }

    @Override
    protected void initView() {
        dataBinding.worksRv.setLayoutManager(new GridLayoutManager(getContext(), 2));
        workAdapter = new WorkAdapter(likeVideoBeans);
        dataBinding.worksRv.setAdapter(workAdapter);
    }

    @Override
    protected Class<WorksViewModel> getViewModel() {
        return WorksViewModel.class;
    }
}